var app = getApp();

Page({
    data: {
        _is_load: !0,
        payopen: !1,
        _overrule: !1
    },
    onLoad: function() {
        var e = this;
        app.util.footer(this), app.util.getUserInfo(function(a) {
            var t = this;
            e.setData({
                userInfo: a,
                avatar: a.memberInfo.avatar,
                nickname: a.memberInfo.nickname
            }), e.data.userInfo.memberInfo.nickname || (app.globalData.userInfo ? this.setData({
                userInfo2: app.globalData.userInfo,
                avatar: app.globalData.userInfo.avatarUrl,
                nickname: app.globalData.userInfo.nickName,
                hasUserInfo: !0
            }) : this.data.canIUse ? app.userInfoReadyCallback = function(a) {
                t.setData({
                    userInfo2: a.userInfo,
                    avatar: a.userInfo.avatarUrl,
                    hasUserInfo: !0
                });
            } : wx.getUserInfo({
                success: function(a) {
                    app.globalData.userInfo = a.userInfo, t.setData({
                        userInfo2: a.userInfo,
                        avatar: a.userInfo.avatarUrl,
                        hasUserInfo: !0
                    });
                }
            }));
        }), app.util.request({
            url: "entry/wxapp/Setup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                e.setData({
                    setup: a.data.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/Card_overrule",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                e.setData({
                    card_overrule: a.data.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/VideoSetup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                e.setData({
                    videosetup: a.data.data
                });
            }
        }), e.data.userInfo.memberInfo || e.setData({
            _wxInfo: !0
        });
    },
    onShow: function() {
        this.onBbbyscm(1), this.setData({
            sysinfo: app.globalData.sysinfo,
            _is_load: !0
        });
    },
    onBbbyscm: function() {
        var t = this;
        app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                0 == a.data.errno && 0 == a.data.data && wx.showModal({
                    title: "提示",
                    content: "你还没有创建名片，不能使用个人中心全部功能",
                    confirmText: "创建名片",
                    success: function(a) {
                        a.confirm ? wx.navigateTo({
                            url: "../../card/edit/card-edit"
                        }) : a.cancel && t.setData({
                            _is_load: !1
                        });
                    }
                }), t.setData({
                    card_info: a.data.data,
                    cardid: a.data.data.id,
                    card_sid: a.data.data.id,
                    cardname: a.data.data.cardname,
                    p_coll: a.data.data.money,
                    dayover: Math.floor(a.data.data.over_syts / 86400),
                    hourover: Math.floor((a.data.data.over_syts - 24 * Math.floor(a.data.data.over_syts / 86400) * 3600) / 3600),
                    dayv: Math.floor(a.data.data.syts / 86400),
                    hourv: Math.floor((a.data.data.syts - 24 * Math.floor(a.data.data.syts / 86400) * 3600) / 3600)
                }), app.util.request({
                    url: "entry/wxapp/GetWords",
                    data: {
                        m: "bbyscm_card",
                        cardid: t.data.card_sid
                    },
                    success: function(a) {
                        t.setData({
                            words: a.data.data,
                            wordsid: a.data.data.id,
                            day: Math.floor(a.data.data.syts / 86400),
                            hour: Math.floor((a.data.data.syts - 24 * Math.floor(a.data.data.syts / 86400) * 3600) / 3600),
                            _is_load: !1
                        });
                    }
                });
            }
        });
    },
    videopayopen: function() {
        var a = this;
        0 < a.data.videosetup.pay_coll - a.data.card_info.money ? this.setData({
            pay_coll: a.data.videosetup.pay_coll,
            bupay_coll: (a.data.videosetup.pay_coll - a.data.card_info.money).toFixed(2),
            pay_term: "postvideo",
            payopen: !0
        }) : this.setData({
            pay_coll: a.data.videosetup.pay_coll,
            bupay_coll: (0).toFixed(2),
            pay_term: "postvideo",
            payopen: !0
        });
    },
    checkboxChange: function(a) {
        var t = this;
        a.detail.value[0] ? 0 < t.data.pay_coll - a.detail.value[0] ? t.setData({
            bupay_coll: (t.data.pay_coll - a.detail.value[0]).toFixed(2)
        }) : t.setData({
            bupay_coll: (0).toFixed(2)
        }) : t.setData({
            bupay_coll: t.data.pay_coll
        });
    },
    paycloes: function(a) {
        this.setData({
            payopen: !1
        });
    },
    mails_admin: function(a) {
        wx.navigateTo({
            url: "../../card/mailad/mailad"
        });
    },
    words: function(a) {
        wx.navigateTo({
            url: "../words/words?card_id=" + a.currentTarget.dataset.mid
        });
    },
    citylist: function(a) {
        wx.navigateTo({
            url: "../../city/citys/citys?cardid=" + a.currentTarget.dataset.id
        });
    },
    videopay: function(a) {
        wx.navigateTo({
            url: "../videopay/videopay?card_id=" + a.currentTarget.dataset.mid
        });
    },
    admin_index: function(a) {
        wx.navigateTo({
            url: "../../examine/index/index"
        });
    },
    call_phone_bind: function(a) {
        var t = a.currentTarget.id;
        "" != t && wx.makePhoneCall({
            phoneNumber: t
        });
    },
    onNavigateTap: function(a) {
        wx.openSetting({});
    },
    postvideo: function(a) {
        var t = this;
        t.setData({
            btn_disabled: !0,
            submitIsLoading: !0,
            payopen: !1
        }), JSON.stringify(a.detail.value);
        var e = a.detail.formId, s = t.data.card_sid, o = t.data.cardname, n = 365, d = t.data.bupay_coll, i = t.data.pay_coll - d;
        if (!s) return wx.showModal({
            title: "提示",
            content: "获取信息失败",
            showCancel: !1,
            success: function(a) {
                a.confirm, t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1;
        0 < d ? (t.setData({
            pay: !0
        }), app.util.request({
            url: "entry/wxapp/Pay",
            data: {
                m: "bbyscm_card",
                cost: d,
                days: n,
                id: s
            },
            method: "POST",
            success: function(a) {
                wx.requestPayment({
                    timeStamp: a.data.timeStamp,
                    nonceStr: a.data.nonceStr,
                    package: a.data.package,
                    signType: a.data.signType,
                    paySign: a.data.paySign,
                    success: function(a) {
                        t.setData({
                            Msg: a.errMsg,
                            pay: !1
                        }), "requestPayment:ok" == t.data.Msg && (wx.showToast({
                            title: "提交中...",
                            icon: "loading",
                            duration: 1e4
                        }), app.util.request({
                            url: "entry/wxapp/PostWordspay",
                            data: {
                                m: "bbyscm_card",
                                cardid: s,
                                wordsid: s,
                                pay_class: 3,
                                days: n,
                                coll: d,
                                yepay_coll: i
                            },
                            method: "POST"
                        }), app.util.request({
                            url: "entry/wxapp/PostVideopay",
                            data: {
                                m: "bbyscm_card",
                                cardid: s,
                                days: n,
                                yepay_coll: i
                            },
                            method: "POST",
                            success: function(a) {
                                0 == a.data.errno ? (app.util.request({
                                    url: "entry/wxapp/Message1",
                                    data: {
                                        m: "bbyscm_card",
                                        openid: t.data.card_info.openid,
                                        form_id: e,
                                        pay_class: 3,
                                        pay_classid: s,
                                        coll: d,
                                        days: n,
                                        cardname: o,
                                        page: "pages/user/index/index"
                                    },
                                    success: function(a) {
                                        wx.reLaunch({
                                            url: ""
                                        });
                                    }
                                }), wx.showModal({
                                    title: "提示",
                                    content: "提交成功",
                                    showCancel: !1,
                                    success: function(a) {
                                        t.setData({});
                                    }
                                })) : wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm;
                                    }
                                });
                            },
                            fail: function(a) {
                                wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm;
                                    }
                                });
                            },
                            complete: function() {
                                wx.hideToast();
                            }
                        }));
                    },
                    fail: function(a) {
                        t.setData({
                            pay: !1,
                            btn_disabled: !1,
                            submitIsLoading: !1
                        }), wx.showToast({
                            title: "支付失败",
                            duration: 1e3
                        });
                    }
                });
            }
        })) : (app.util.request({
            url: "entry/wxapp/PostWordspay",
            data: {
                m: "bbyscm_card",
                cardid: s,
                wordsid: s,
                pay_class: 3,
                days: n,
                coll: d,
                yepay_coll: i
            },
            method: "POST"
        }), app.util.request({
            url: "entry/wxapp/PostVideopay",
            data: {
                m: "bbyscm_card",
                cardid: s,
                days: n,
                yepay_coll: i
            },
            method: "POST",
            success: function(a) {
                console.log("4", a), 0 == a.data.errno && wx.showModal({
                    title: "提示",
                    content: "提交成功",
                    showCancel: !1,
                    success: function(a) {
                        t.setData({
                            btn_disabled: !1,
                            submitIsLoading: !1
                        });
                    }
                });
            }
        })), this.onBbbyscm(1);
    },
    over_rule: function(a) {
        this.setData({
            _overrule: !this.data._overrule
        });
    },
    overrulepayopen: function(a) {
        0 < a.detail.target.dataset.coll - this.data.card_info.money ? this.setData({
            pay_coll: a.detail.target.dataset.coll,
            days: a.detail.target.dataset.days,
            bupay_coll: (a.detail.target.dataset.coll - this.data.card_info.money).toFixed(2),
            pay_term: "overrule",
            payopen: !0
        }) : this.setData({
            pay_coll: a.detail.target.dataset.coll,
            days: a.detail.target.dataset.days,
            bupay_coll: (0).toFixed(2),
            pay_term: "overrule",
            payopen: !0
        });
    },
    overrule: function(a) {
        var t = this;
        t.setData({
            btn_disabled: !0,
            submitIsLoading: !0,
            payopen: !1,
            _overrule: !this.data._overrule
        }), JSON.stringify(a.detail.value);
        var e = a.detail.formId, s = t.data.card_sid, o = t.data.cardname, n = t.data.days, d = t.data.bupay_coll, i = t.data.pay_coll - d;
        if (!s) return wx.showModal({
            title: "提示",
            content: "获取信息失败",
            showCancel: !1,
            success: function(a) {
                a.confirm, t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1;
        0 < d ? (t.setData({
            pay: !0
        }), app.util.request({
            url: "entry/wxapp/Pay",
            data: {
                m: "bbyscm_card",
                cost: d,
                days: n,
                id: s
            },
            method: "POST",
            success: function(a) {
                wx.requestPayment({
                    timeStamp: a.data.timeStamp,
                    nonceStr: a.data.nonceStr,
                    package: a.data.package,
                    signType: a.data.signType,
                    paySign: a.data.paySign,
                    success: function(a) {
                        t.setData({
                            Msg: a.errMsg,
                            pay: !1
                        }), "requestPayment:ok" == t.data.Msg && (wx.showToast({
                            title: "提交中...",
                            icon: "loading",
                            duration: 1e4
                        }), app.util.request({
                            url: "entry/wxapp/PostWordspay",
                            data: {
                                m: "bbyscm_card",
                                cardid: s,
                                wordsid: s,
                                pay_class: 4,
                                days: n,
                                coll: d,
                                yepay_coll: i
                            },
                            method: "POST"
                        }), app.util.request({
                            url: "entry/wxapp/PostOver",
                            data: {
                                m: "bbyscm_card",
                                cardid: s,
                                days: n,
                                yepay_coll: i
                            },
                            method: "POST",
                            success: function(a) {
                                0 == a.data.errno ? (app.util.request({
                                    url: "entry/wxapp/Message1",
                                    data: {
                                        m: "bbyscm_card",
                                        openid: t.data.card_info.openid,
                                        form_id: e,
                                        pay_class: 4,
                                        pay_classid: s,
                                        coll: d,
                                        days: n,
                                        cardname: o,
                                        page: "pages/card/ranking/ranking"
                                    },
                                    success: function(a) {
                                        wx.reLaunch({
                                            url: ""
                                        });
                                    }
                                }), wx.showModal({
                                    title: "提示",
                                    content: "提交成功",
                                    showCancel: !1,
                                    success: function(a) {
                                        t.setData({
                                            btn_disabled: !1,
                                            submitIsLoading: !1
                                        });
                                    }
                                })) : wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm;
                                    }
                                });
                            },
                            fail: function(a) {
                                wx.showModal({
                                    title: "提示",
                                    content: a.data.message,
                                    showCancel: !1,
                                    success: function(a) {
                                        a.confirm;
                                    }
                                });
                            },
                            complete: function() {
                                wx.hideToast();
                            }
                        }));
                    },
                    fail: function(a) {
                        t.setData({
                            pay: !1,
                            btn_disabled: !1,
                            submitIsLoading: !1,
                            videopay: !1
                        }), wx.showToast({
                            title: "支付失败",
                            duration: 1e3
                        });
                    }
                });
            }
        })) : (app.util.request({
            url: "entry/wxapp/PostWordspay",
            data: {
                m: "bbyscm_card",
                cardid: s,
                wordsid: s,
                pay_class: 4,
                days: n,
                coll: d,
                yepay_coll: i
            },
            method: "POST"
        }), app.util.request({
            url: "entry/wxapp/PostOver",
            data: {
                m: "bbyscm_card",
                cardid: s,
                days: n,
                yepay_coll: i
            },
            method: "POST",
            success: function(a) {
                0 == a.data.errno && wx.showModal({
                    title: "提示",
                    content: "提交成功",
                    showCancel: !1,
                    success: function(a) {
                        t.setData({
                            btn_disabled: !1,
                            submitIsLoading: !1
                        });
                    }
                });
            }
        })), this.onBbbyscm(1);
    },
    onNavigateTaptb: function(a) {
        var t = a.currentTarget.dataset.url, e = a.currentTarget.dataset.wx_appid, s = a.currentTarget.dataset.wx_path;
        e ? wx.navigateToMiniProgram({
            appId: e,
            path: s,
            extraData: {
                foo: "bar"
            },
            envVersion: "develop",
            success: function(a) {}
        }) : wx.navigateTo({
            url: "../info/info?card_id=" + t
        });
    },
    collection: function(a) {
        wx.navigateTo({
            url: "../../card/collection/collection"
        });
    },
    exchange: function(a) {
        wx.navigateTo({
            url: "../exchange/exchange"
        });
    },
    onPullDownRefresh: function() {},
    tap_scanner: function(a) {
        wx.navigateTo({
            url: "../../card/ai_ocr/ai_ocr"
        });
    },
    p_explain: function(a) {
        this.setData({
            explain: !this.data.explain
        });
    }
});